import {fileURLToPath, URL} from 'node:url'
import type {ConfigEnv, UserConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import vueSetupExtend from 'vite-plugin-vue-setup-extend'
import Inspector from 'vite-plugin-vue-inspector'
import {svgUtil} from './src/utils/svgUtil'
import {isProd} from './src/utils/viteUtil'
import vueJsx from '@vitejs/plugin-vue-jsx'

// 图标路径和前缀配置
const pathAndPrefixMap: Map<string, string> = new Map()
pathAndPrefixMap.set('./src/assets/icons/svg/cus/', 'local-cus')
pathAndPrefixMap.set('./src/assets/icons/svg/ant/', 'local-ant')
pathAndPrefixMap.set('./src/assets/icons/svg/aliIntl/', 'local-aliIntl')

// https://vitejs.dev/config/
const viteConfig = ({mode}: ConfigEnv): UserConfig => {
	return {
		plugins: [
			vue(),
			vueSetupExtend(),
			vueJsx(),
			svgUtil(pathAndPrefixMap),
			Inspector({
				toggleComboKey: 'control-shift'
			})
		],
		resolve: {
			alias: {
				'@': fileURLToPath(new URL('./src', import.meta.url)),
				path: 'path-browserify',
				'vue-i18n': isProd(mode) ? 'vue-i18n/dist/vue-i18n.cjs.prod.js' : 'vue-i18n/dist/vue-i18n.cjs.js'
			}
		},
		build: {
			sourcemap: false
		}
	}
}

export default viteConfig
